var memberUtil = require('../../utils/memberUtil');
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    shop: [
      { img: '/images/s_2.jpg', name: '美白补水面膜', pic: '98', num: '10' },
      { img: '/images/s_2.jpg', name: '美白补水面膜', pic: '2188', num: '100' },
      { img: '/images/s_2.jpg', name: '美白补水面膜', pic: '108', num: '80' },
      { img: '/images/s_2.jpg', name: '美白补水面膜', pic: '38', num: '1000' },
    ],
imagesUrl: app.globalData.baseImageUrl,
    baseServerImageUrl: app.globalData.baseUrl,
    showImages:app.globalData.baseImageUrl+'/images/s_1.jpg',
    navigationBarBackGround:'#099CEC',
    tid:0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that=this;
    that.setData({
      userInfo: wx.getStorageSync("loginUserInfo").userInfo==undefined?"":wx.getStorageSync("loginUserInfo").userInfo
    });
      if(options.tid!='belongto' && options.tid) {
        that.goodsList(options.tid);
      }else if(options.tid=='belongto'){
          that.jif();
      }
      that.imagesSixShow(options.tid);
      memberUtil.shareDL(app,options,"2",that);
  },
  //调用积分专区商品列表
  goodsList: function (categoryIds){
    var that=this;
    var categoryIdJson={
      categoryId: categoryIds
    }
    wx.showLoading({
      title: '数据加载中',
      mask: true
    })
    wx.request({
      url: app.globalData.baseUrl + "/goods/findGoodsListByCategoryId",
      data: JSON.stringify(categoryIdJson),
      header: app.globalData.headerPost,
      method: 'POST',
      success: function (e) {
        if (e.statusCode == 200) {
          that.setData({
            shop: e.data
          })
        } else {//调用接失败
          wx.showModal({
            title: "通知",
            content: "接口调用失败",
            showCancel: false,
            confirmText: "确定"
          })
        }
        wx.hideLoading();
      },
      fail: function (e) {
        wx.showModal({
          title: "通知",
          content: "接口调用失败",
          showCancel: false,
          confirmText: "确定"
        })
        wx.hideLoading();
      }
    })
  },
  //调用积分
  jif:function(){
    var that=this;
    wx.request({
      url: app.globalData.baseUrl + "/goods/integralMall",
      header: app.globalData.headerPost,
      method: 'GET',
      success: function (e) {
        if (e.statusCode == 200) {
          that.setData({
            shop: e.data
          })
        } else {//调用接失败
          wx.showModal({
            title: "通知",
            content: "系统开小差了，请稍后再调",
            showCancel: false,
            confirmText: "确定"
          })
        }
        wx.hideLoading();
      },
      fail: function (e) {
        wx.showModal({
          title: "通知",
          content: "系统开小差了，请稍后再调",
          showCancel: false,
          confirmText: "确定"
        })
        wx.hideLoading();
      }
    })
  },
  //判断图片显示
  imagesSixShow:function(order){
    var that=this;
    var background="";
    var images=that.data.imagesUrl+"/images/a1.jpg?234";
    if(order==4){//康养系列 a6 099CEC
      images=that.data.imagesUrl+"/images/a6.jpg?234";
      background="#EED902";
    }else if(order==3){//壳好食品  a2 8154E8
      images=that.data.imagesUrl+"/images/a2.jpg?234";
      background="#6733DE";
    }else if(order==2){//壳好用品  a1 FF8301
      images=that.data.imagesUrl+"/images/a5.jpg?234";
      background="#C43855";
    }else if(order==6){//睡眠系列  a4 0F6CB8
      images=that.data.imagesUrl+"/images/a1.jpg?234";
      background="#FE6601";
    }else if(order=='belongto'){//积分专区  a3 AC06F2
      images=that.data.imagesUrl+"/images/a3.jpg";
      background="#6F049F";
    }else if(order==5){//洗化用品  a5 FC436D
      images=that.data.imagesUrl+"/images/a4.jpg?t645";
      background="#08B7D2";
    }
    that.setData({
      showImages:images,
      navigationBarBackGround:background,
      tid:order
    })

  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    var that=this;
    return {
      title: '我的二维码',
      path: "/pages/shop/shopList?parentId=" + that.data.userInfo.id + "&enterType=0&aType=1&tid="+that.data.tid,
      imageUrl: app.globalData.loginUserInfo.erweimaUrl
    }
  },
  //页面跳转
  goodsDetailNavigate:function(e){
    wx.showLoading({
      title: '数据加载中',
      mask: true
    })
    wx.hideLoading();
    var goodsId=e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '/pages/shop/shopDt?goodsId='+goodsId
    })

  }
})